package com.dongzili.postgresql.common.vo;

import com.baomidou.mybatisplus.annotation.EnumValue;
import com.fasterxml.jackson.annotation.JsonFormat;
import lombok.*;

import javax.validation.Valid;
import java.time.LocalDateTime;
import java.util.List;
import java.util.Map;

@Getter
@Setter
@AllArgsConstructor
public class PageRequest<T> {

    /** 当前页数，从1开始 */
    private Integer current;
    /** 每页记录数 **/
    private Integer size;
    /** 总数 **/
    private Integer total;
    /**搜索关键字*/
    private String keyword;
    /** 请求数据实体 */
    @Valid
    private T entity;
    /** 请求数据实体数组 */
    @Valid
    private List<T> entities;
    /** 消息ID */
    private String messageId;
    /** 模糊搜索承载实体 */
    private T likeEntity ;

    private Map<String, List<?>> in;
    private Map<String, List<?>> notIn;
    /** 排序字段 */
    private List<OrderVo> orders;
    /** 根据指定时间区间查询字段 */
    private Map<String, QueryPeriodVo> queryPeriod;


    public PageRequest() {
        current = 1;
        size = 10;
    }


    /**
     * 排序对象
     */
    @Data
    @AllArgsConstructor
    @NoArgsConstructor
    public static class OrderVo {
        private String filedName;
        private OrderType orderType;
    }

    /**
     * 排序方式
     */
    @Getter
    public enum OrderType {
        /**
         * 降序
         */
        Desc(1),
        /**
         * 升序
         */
        Asc(2)
        ;

        @EnumValue//标记数据库存的值
        private final int value;

        OrderType(int value) {
            this.value = value;
        }
    }

    /**
     * 查询期间
     */
    @Getter
    @Setter
    @AllArgsConstructor
    @NoArgsConstructor
    public static class QueryPeriodVo {

        @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
        private LocalDateTime startTime;

        @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
        private LocalDateTime endTime;


    }

}



